# Scrapy settings for tutorial project
#
# For simplicity, this file contains only the most important settings by
# default. All the other settings are documented here:
#
#     http://doc.scrapy.org/topics/settings.html
#


BOT_NAME = 'goofish_spider_Bot'
BOT_VERSION = '1.0'

SPIDER_MODULES = ['spiders']
NEWSPIDER_MODULE = 'spiders'
USER_AGENT = '%s/%s' % (BOT_NAME, BOT_VERSION)

ITEM_PIPELINES = {
    # "pipelines.ugpipeline.UltimateGuitarPipeline": 1,
}

##图片、文件配置###############################################################
# 设置存储路径
IMAGES_STORE = './temp/images'    # 图片存储目录
FILES_STORE = './temp/files'      # 文件存储目录（可选）

# 可选：限制图片尺寸和格式
# IMAGES_THUMBS = {            # 生成缩略图（可选）
#     'small': (50, 50),
#     'big': (270, 270),
# }
# IMAGES_MIN_HEIGHT = 100      # 最小高度（过滤小图）
# IMAGES_MIN_WIDTH = 100       # 最小宽度

##日志配置###############################################################
LOG_ENABLED = True # 默认True，设为False完全禁用日志
LOG_STDOUT = True  # 是否将print输出到日志（默认False）
LOG_FILE = './logs/scrapy.log'  # 指定日志文件路径

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,  # 保留Scrapy原有Logger
    'formatters': {
        'verbose': {
            'format': '%(asctime)s [%(levelname)s] %(name)s: %(message)s',
            'datefmt': '%Y-%m-%d %H:%M:%S'
        },
    },
    'handlers': {
        'console': {
            'class': 'logging.StreamHandler',
            'formatter': 'verbose',
            'level': 'DEBUG',  # 控制台输出INFO及以上级别
        },
        'file': {
            'class': 'logging.handlers.TimedRotatingFileHandler',
            'filename': 'scrapy.log',
            'when': 'midnight', #每天轮转
            'backupCount': 7, # 保留7天
            'formatter': 'verbose',
            'level': 'DEBUG',  # 文件记录DEBUG及以上级别
        },
    },
    'loggers': {
        'scrapy': {
            'handlers': ['console', 'file'],
            'level': 'DEBUG',  # Scrapy核心日志级别
            'propagate': False,
        },
        'my_spider': {  # 自定义爬虫的Logger
            'handlers': ['file'],
            'level': 'INFO',
        },
    },
}



## SELENIUM 相关配置 ###############################################################
from shutil import which

SELENIUM_DRIVER_NAME = 'chrome'
#which('chromedriver')  # ChromeDriver路径
SELENIUM_DRIVER_EXECUTABLE_PATH = which('chromedriver.exe')   #r'D:\chromedriver-win64\chromedriver.exe' 
SELENIUM_DRIVER_ARGUMENTS = ['--headless']  # 无头模式

DOWNLOADER_MIDDLEWARES = {
    'scrapy_selenium.SeleniumMiddleware': 800
}

